import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/1/20
 * Time:16:10
 **/
public class Main {


    public static void main6(String[] args) {
        String s1="abc"+"def";
        String s2=new String(s1);
        if(s1.equals(s2))
            System.out.println(".equals succeeded");
        if(s1==s2)
            System.out.println("==succeeded");

    }
        public static String reverse(String string,int left,int right){
            char[] chars = string.toCharArray();
            while (left < right) {
                char tmp = chars[left];
                chars[left] = chars[right];
                chars[right] = tmp;
                left++;
                right--;
            }
            return String.valueOf(chars);
        }
        public static String reverseK(String str,int k){
            if(str == null||k <= 0||k>str.length()){
                return null;
            }
            str = reverse(str,0,k-1);
            str = reverse(str,k,str.length()-1);
            str = reverse(str,0,str.length()-1);
            return str;
        }
        public static void main5(String[] args) {
            Scanner scan = new Scanner(System.in);
            int k = scan.nextInt();
            String str = scan.next();
            String ret = reverseK(str,k);
            System.out.println(ret);
        }
    public static String reverse(String string) {
        char[] chars = string.toCharArray();
        int i = 0;
        int j = chars.length-1;
        while (i<j){
            char tmp = chars[i];
            chars[i] = chars[j];
            chars[j] = tmp;
            i++;
            j--;
        }
        //将数组转换为字符串
        //return chars;
        //return new String(chars);
        //return String.copyValueOf(chars);
        return String.valueOf(chars);
    }

    public static void main4(String[] args) {
        String str = "hello";
        System.out.println(reverse(str));
    }

    public static void main3(String[] args) {
        char[] value = {'h','e','l','l','o'};
        String str1 = new String (value,1,2);
        System.out.println(str1);

        String str = "hello";
        char ch = str.charAt(1);//拿出某位的字符，不能超出范围，否则越界
        System.out.println(ch);

        char[] chars = str.toCharArray();//将字符串转换为数组
        System.out.println(Arrays.toString(chars));
    }

    public static void main2(String[] args) {//反射
        String str = "abc";
        Class c1 = String.class;
        try {
            Field field = c1.getDeclaredField("value");
            field.setAccessible(true);
            char[] value = (char[]) field.get(str);
            System.out.println(Arrays.toString(value));
            System.out.println(str);
            value[0]='q';
            System.out.println(str);
        } catch (IllegalAccessException e) {
                e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
    public static void main1(String[] args) {
        String str = "hello";
        System.out.println(str);
        String str2 = new String("hello");
        System.out.println(str2);
        char[] value = {'h','e','l','l','o'};
        String str3 = new String(value);
        System.out.println(str3);
        String str4 = new String ("hel")+new String("lo");
        String str5 = new String("hel")+"lo";
        String str6 = "hel"+"lo";
        System.out.println(str == str2);
        System.out.println(str2 == str3);
        System.out.println(str == str3);
        System.out.println(str == str4);
        System.out.println(str == str5);
        System.out.println(str == str6);
    }
}

